#include <iostream>
#include <croncpp/Cron.h>
#include <date/date.h>
#include <unistd.h>

int64_t GetNowTime()
{
    return std::chrono::duration_cast<std::chrono::seconds>(std::chrono::system_clock::now().time_since_epoch()).count();
}

int main()
{
    int nstate = 0;

    croncpp::Cron cron;

//    0:0:4:*:*:3,5,7 // 每周三五七的早上四点
//    0:0:4:*:*:2,4,6 // 每周二四六的早上四点

    cron.add_schedule("open" , "0,5,10,15,20,25,30,35,40,45,50,55 * * * * ?", 
    [&nstate](auto&){
        nstate = 1;
        std::cout<< nstate << std::endl;
        std::cout <<"Now Time is: " << GetNowTime() << " open" << std::endl;
    });

    cron.add_schedule("close", "2,7,12,17,22,27,32,37,42,47,52,57 * * * * ?",
    [&nstate](auto&){
        nstate = 0;
        std::cout<< nstate << std::endl;
        std::cout <<"Now Time is: " << GetNowTime() << " close" << std::endl;
    });

    while(true)
    {
        cron.tick();
        usleep(1000);
    }

    return 0;
}